/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dinotrack.struts;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Mathews
 */
public class ComentarioForm extends org.apache.struts.action.ActionForm {

    private static int id;
    private String nomUsuario;
    private String comentario;
    private String error;
    private StringBuilder inf;

    /**
     *
     */
    public ComentarioForm() {
        super();
        inf=new StringBuilder();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (id < 1) {
            errors.add("usuario", new ActionMessage("error.usuario.required"));
        }

        if (nomUsuario == null || nomUsuario.length() < 1) {
            errors.add("contraseña", new ActionMessage("error.contraseña.required"));
        }

        if (comentario == null || comentario.length() < 1) {
            errors.add("nombre", new ActionMessage("error.nombre.required"));
        }
        // TODO: add 'error.name.required' key to your resources

        return errors;
    }

    public void setError(String error) {
        inf.append("* " + error + "\n");
        this.error =
                "<span style='color:red'>Ingrese los datos solicitados: " + inf + "</span>";
    }

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        // reset properties
        id = 0;
        nomUsuario = "";
        comentario = "";
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the nomUsuario
     */
    public String getNomUsuario() {
        return nomUsuario;
    }

    /**
     * @param nomUsuario the nomUsuario to set
     */
    public void setNomUsuario(String nomUsuario) {
        this.nomUsuario = nomUsuario;
    }

    /**
     * @return the comentario
     */
    public String getComentario() {
        return comentario;
    }

    /**
     * @param comentario the comentario to set
     */
    public void setComentario(String comentario) {
        this.comentario = comentario;
    }
}
